export default function OutputSize() {
  return {
    name: 'output-size',
    
    writeBundle(outputOptions, bundle) {
        console.log(`文件类型  大小  文件路径`);
      Object.entries(bundle).forEach(([fileName, file]) => {
        let size = 0;

        if (file.type === 'chunk') {
          size = Buffer.byteLength(file.code, 'utf8');
        } else if (file.type === 'asset') {
          size = Buffer.byteLength(
            typeof file.source === 'string' ? file.source : file.source.toString(),
            'utf8'
          );
        }

        const sizeKb = (size / 1024).toFixed(2).padStart(8, ' ');
        const typeLabel = file.type === 'chunk' ? 'JS   ' : 'Asset';

        console.log(`${typeLabel}  ${sizeKb} KB  ${fileName} `);
      });
    }
  };
}
